source config.sh

if [ "$1" = "" ];then
	echo "Please input user"
	exit
fi
if [ "$2" = "" ];then
	echo "Please input server ID"
	exit
fi
user=$1
ServerID=$2

$GetAllRelatedInstances $user $ServerID | while read line; 
do 
	instance=$(echo "$line"| awk {'print $1'})
	ifRunning=$(echo "$line"| awk {'print $2'})
	echo "$RebootOrStartRelatedInstances: $instance $ifRunning"
	Command="ec2-start-instances"
	if [ "$ifRunning" = "running" ];then
		Command="ec2-reboot-instances"
	fi		
	echo "$RebootOrStartRelatedInstances: $Command $user $instance"
	($Command $instance) &	
done

exit


















DescribeInstances=$(ec2-describe-instances)
for instance in $(cat $InstanceUserFile | grep "$user" | awk {'print $1'}); do 
	ifRunning=$(echo "$DescribeInstances" | grep "$instance" | awk {'print $6'})
	Command="ec2-start-instances"
	if [ "$ifRunning" = "running" ];then
		Command="ec2-reboot-instances"
	fi	
	if [ "$instance" = "$ServerID" ];then
		echo "$Command server $instance"
		($Command $instance)&	
	else
		TempServer=$(cat $InstanceServerFile | grep "$instance" | awk {'print $2'})
		if [ "$ServerID" = "$TempServer" ];then
			echo "$Command client $instance"
			($Command $instance)&
		fi
	fi

done